package com.yanyan.sannuomin.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yanyan.sannuomin.domain.SccDrugstore;
import com.yanyan.sannuomin.pharvo.Phar1;
import com.yanyan.sannuomin.pharvo.Phar2;
import com.yanyan.sannuomin.result.Result;
import com.yanyan.sannuomin.result.ResultCode;
import com.yanyan.sannuomin.service.PharService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/user1")
@Api(tags = "检测者管理",description = "提供对医院人员的查询")
@RestController
@CrossOrigin
@EnableSwagger2
public class PharController {
    @Resource
    private PharService pharServiceImpl;

    @RequestMapping(value = "findYD1", method = RequestMethod.GET)
    @ApiOperation(value = "查询用户", notes = "根据条件分页查询", httpMethod = "GET")
    public Result findYD1(Integer page, Integer limit, String searchParams) throws  Exception{
        System.out.println("搜索条件："+searchParams);
        ObjectMapper objectMapper = new ObjectMapper();
        Phar1 phar1 = null;
        if(searchParams != null){
            phar1= objectMapper.readValue(searchParams, Phar1.class);
        }
        System.out.println("搜索结果："+phar1);
        Page page1 = PageHelper.startPage(page, limit);
        List<Phar1> phar1Vo1 = pharServiceImpl.findPhar1(phar1);
        PageInfo pageInfo=new PageInfo(phar1Vo1);
        return Result.ok(ResultCode.SUCCESS,pageInfo.getTotal(),phar1Vo1);

    }
    @RequestMapping(value = "findYD2", method = RequestMethod.GET)
    @ApiOperation(value = "查询用户", notes = "根据条件分页查询", httpMethod = "GET")
    public Result findAccount(Integer page, Integer limit, String searchParams) throws  Exception{
        System.out.println("搜索条件："+searchParams);
        ObjectMapper objectMapper = new ObjectMapper();
        Phar2 phar2 = null;
        if(searchParams != null){
            phar2= objectMapper.readValue(searchParams, Phar2.class);
        }
        System.out.println("搜索结果："+phar2);
        Page page1 = PageHelper.startPage(page, limit);

        List<Phar2> phar2Vos = pharServiceImpl.findPhar2(phar2);
        PageInfo pageInfo=new PageInfo(phar2Vos);
        System.out.println(phar2Vos);
        return Result.ok(ResultCode.SUCCESS,pageInfo.getTotal(),phar2Vos);

    }
    @RequestMapping(value = "SsjSelect1", method = RequestMethod.GET)
    @ApiOperation(value = "查询用户", notes = "根据条件查询", httpMethod = "GET")
    public Result FdSelect(SccDrugstore sccDrugstore) throws  Exception{

        List<SccDrugstore> sdv1 = pharServiceImpl.SsjSelect(sccDrugstore);
        return Result.ok(ResultCode.SUCCESS,sdv1);

    }
}
